<?

$dataup = true;
$uprun  = true;

/**
* Check the entry
*
*/
for($iRow = 0; $iRow < $_SESSION["init_num"]; $iRow++){
  
  /**
  * Check for each master detail
  *
  */
  if($_POST["modelEnt"][$iRow] == '' ||
     $_POST["qtyEnt"][$iRow]   == ''){
    
    for($iNext = ($iRow + 1); $iNext < $_SESSION["init_num"]; $iNext++ ){
      
      if($_POST["modelEnt"][$iNext] != '' ||
         $_POST["qtyEnt"][$iNext]   != ''){
        
        $uprun = false;
    
        usrError("Invalid Entry at : ".($iNext + ARRAY_NUMBER)." ");
        
        break;
      }
    }
    
    if($uprun == false){
      
      /* out of this loop */
      break;
    }
  }else{
    
    $dataup++;
  }
}

if($dataup == 0 ){
	
	usrError("ERROR: Data is empty");
	
	jumpTo(2,"../".$_SESSION["source_caller"]);
}

if($uprun == true && $dataup > 0){
	
	/**
	* We are good with details
	* continue with the header check 
	*
	*/
	if($_POST["trDateEnt"]    != '' ){
		
		//everything is good
		//open confirmation form
		if(!$_POST["confirm"] && !$_POST["back"]){
			
			require("entry_upload_confirm.php");
		}elseif($_POST["back"]){
			
			require("entry_restore_me.php");
		}else{
			
			/**
			* Prepare to upload
			* modify mode is on 
			*
			*/
			if($_SESSION["modify_mode"] == "Y" && $_SESSION["jid"] != ''){
				
				/**
				* Reset the modify_mode
				*
				*/
				$_SESSION["modify_mode"] = "N";
				
				require("upmodifytodb.php");
			}elseif($_SESSION["modify_mode"] != "Y"){ //if modify mode is off
				
				require("upentrytodb.php");
			}else{
				
				echo "Unknown Upload Task!!!\n";
			}
		}
	}else{
		
		usrError("Error:  No empty field allowed please make a correction reason: header incompleted");
		
		require("entry_restore_me.php");
	}
}

if($uprun == false){
	
	echo "Restoring...\n";
	$restore  = 0;
	$uprun    = 0;
	$dataup   = 0;
	
	require("entry_restore_me.php");
}
?>